
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const normalizeHtmlWhitespace = require('normalize-html-whitespace');

module.exports = {

  entry: path.join(__dirname, './src', 'index.js'),
  
  output: {
    filename: 'index.js',
    path: path.resolve(__dirname, './dist')
  },
  
  module: {
    rules: [
      {
        test: /\.js?$/,
        include: [
          path.resolve(__dirname, './src')
        ],
        exclude: [
          path.resolve(__dirname, './node_modules')
        ], 
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: [
                "env",
                "stage-0",
                "react",
              ]
            }
          }
        ]
      },
      {
        test: /\.rt$/,
        include: [
          path.resolve(__dirname, './src')
        ],
        exclude: [
          path.resolve(__dirname, './node_modules')
        ],
        use: [
          {
            loader: 'react-templates-loader',
            options: {
              modules: 'amd',
              normalizeHtmlWhitespace
            }
          }
        ]
        // loader: 'react-templates-loader?modules=amd'
      }
    ]
  },
  
  resolve: {
    extensions: ['.json', '.js', '.jsx', '.css']
  },
  
  devtool: 'source-map',
  
  devServer: {
    //这个有什么作用还要详细了解
    //publicPath: path.join('/dist/'),
    //内容目录路径
    contentBase: path.join('./dist'),
    //服务器端口
    port: 1111,
    //文件修改自动刷新浏览器
    inline: true
  },

  //插件
  plugins: [
    //html整合插件，负责生成包含目标js文件的html文件
    new HtmlWebpackPlugin({
        template: "./src/index.html",
        filename: "index.html"
    })
  ]
};